<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%-- 分页条的开始 --%>
<div id="page_nav">
    <%-- 点击首页、上一页、下一页、末页，请求 Servlet 获取数据并重定向到本jsp页面 --%>
    <c:if test="${requestScope.page.pageNo > 1}">
        <%-- 如果是第一页，那么不显示首页、上一页
             pageNo > 1 才显示上一页、首页
        --%>
        <a href="${requestScope.page.url}&pageNo=1">首页</a>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo - 1}">上一页</a>
    </c:if>

    <c:choose>
        <%--总页数小于 5 页 的时候， 全部显示--%>
        <c:when test="${requestScope.page.pageTotal <= 5}">
            <c:forEach begin="1" end="${requestScope.page.pageTotal}" var="i">
                <c:if test="${i == requestScope.page.pageNo}">
                    [${i}]
                </c:if>
                <c:if test="${i != requestScope.page.pageNo}">
                    <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                </c:if>
            </c:forEach>
        </c:when>
        <%--总页数大于 5 页 的时候--%>
        <c:when test="${requestScope.page.pageTotal > 5}">
            <c:choose>
                <%--	当前页码为 1 -3 时 --%>
                <c:when test="${requestScope.page.pageNo <= 3}">
                    <c:forEach begin="1" end="5" var="i">
                        <c:if test="${i == requestScope.page.pageNo}">
                            [${i}]
                        </c:if>
                        <c:if test="${i != requestScope.page.pageNo}">
                            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                        </c:if>
                    </c:forEach>
                </c:when>
                <%--	当前页码为 后 3 个时 --%>
                <c:when test="${requestScope.page.pageNo > requestScope.page.pageTotal - 3}">
                    <c:forEach begin="${requestScope.page.pageTotal - 4}" end="${requestScope.page.pageTotal}" var="i">
                        <c:if test="${i == requestScope.page.pageNo}">
                            [${i}]
                        </c:if>
                        <c:if test="${i != requestScope.page.pageNo}">
                            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                        </c:if>
                    </c:forEach>
                </c:when>
                <c:otherwise>
                    <%-- 当前页码在中间的情况， 范围是当前页码 - 2 到 当前页码 +2 的范围--%>
                    <c:forEach begin="${requestScope.page.pageNo - 2}" end="${requestScope.page.pageNo + 2}" var="i">
                        <c:if test="${i == requestScope.page.pageNo}">
                            [${i}]
                        </c:if>
                        <c:if test="${i != requestScope.page.pageNo}">
                            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
                        </c:if>
                    </c:forEach>
                </c:otherwise>
            </c:choose>
        </c:when>
    </c:choose>
    <%--				<a href="#">3</a>--%>
    <%--				【${requestScope.page.pageNo}】--%>
    <%--				<a href="#">5</a>--%>

    <c:if test="${requestScope.page.pageNo < requestScope.page.pageTotal }">
        <%-- 如果是最后一页，那么不显示末页、下一页
             pageNo < 总页数 才显示末页、下一页
        --%>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo + 1}">下一页</a>
        <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageTotal}">末页</a>
    </c:if>

    共${requestScope.page.pageTotal}页，${requestScope.page.pageTotalCount}条记录 到第<input value="${requestScope.page.pageNo}" name="pn" id="pn_input"/>页
    <input id="searchPageBtn" type="button" value="确定">
</div>
<%-- 分页条的结束 --%>